function get_page_size()
{
	var div = document.createElement('div');
	$(div).css(
	{
		position:'absolute',
		top:0,left:0,
		margin:0,border:0,padding:0,
		width:'100%',height:'100%',
		zIndex:99,
		backgroundColor:'transparent'
	}).html(' ');
	$(document.body).append(div);
	var re = {};
	re.height = ($(document.body).height() > $(div).height())?$(document.body).height():$(div).height();
	re.width = ($(document.body).width() > $(div).width())?$(document.body).width():$(div).width();
	document.body.removeChild(div);
	return re;
}

function close_window()
{
	$('[preview]').fadeOut('fast',function()
	{
		$('[preview]').each(function()
		{
			this.parentNode.removeChild(this);
		});
	});
}

function show_login_window()
{
	var bg = document.createElement('div');
	var page = get_page_size();
	$(bg).css(
		{
			height: page.height,
			width: page.width,
			zIndex: '999',
			display:'none',
			position:'absolute',
			top:'0px',
			left:'0px',
			padding:'0px',
			margin:'0px'
		})
		.fadeTo(1,0,function(){ this.style.display = ''; })
		.attr('id','preview_bg')
		.attr('preview','yes')
		.bind('click',close_window);
		
	
	$(document.body).append(bg);
	$(bg).css('background-color','#000000').fadeTo(700,0.5);
	
	var div = document.createElement('div');
	$(div)
		.css(
		{
			height: '100px',
			width: '100px',
			zIndex: '1000',
			backgroundColor: '#fff',
			position:'absolute',
			top:'0px',
			left:'0px',
			padding:'0px',
			margin:'0px'
		})
		.attr('preview','yes');
	
	
	
	$(div)
		.attr('id','preview_img_div')
		.css(
			{ 
				top: $(document).scrollTop()+100, 
				left: $(document).scrollLeft() + ($(window).width() / 2) -50
			})
		.fadeIn()
		.bind('click',function(event){ event.returnValue = false; return false; });
	$(document.body).append(div);

	$.post('login.php?module=ajax',{ },login_window_load);
}


function login_window_load(s)
{
	var div_width = 320;
	var div_height = 250;
	$('#preview_img_div').attr('html',s);

	$('#preview_img_div')
		.animate({ width: div_width , left: $(document).scrollLeft() + ($(window).width() - div_width ) / 2 },700)
		.animate({ height: div_height }, 700 ,function()
		{ 
			var div = document.createElement('div');
			$(div).html($('#preview_img_div').attr('html')).css({ margin:10});
			$(div).fadeTo(1,0,function()
			{
				$('#preview_img_div').append(this).find('div').fadeTo('fast',1);
			});
		});
}

function run_login()
{
	var name = $('#login_input_username').val();
	var pass = $('#login_input_password').val();
	$.post('login.php?module=ajax&m=login',{'name':name,'password':pass},login_callback,'json');
}

function login_callback(data)
{
	if (data.msg) 
		alert(data.msg);
	if (data.eval)
		try{ eval(data.eval); } catch(e) { }
	if (data.success)
	{
		window.location.reload();
	}
}

show_login_window();
login = show_login_window;